import {
    SHOW_TOAST,
    TOAST_TEXT,
    DEGREE_TYPE,
    IS_LOADING,
    MAINTAIN_INFO,
    RECORD_ADDRESS,
    TOKEN,
    ADDRESS,
    CONTACTSID
} from './mutation-type.js'

export default {
    [TOKEN](state, token) {
        window.localStorage.setItem('token', token)
        state.token = token
    },
    [SHOW_TOAST](state, status) { // 信息提示弹框状态
        state.toast = status
    },
    [TOAST_TEXT](state, msg) { // 信息提示弹框内容
        state.toastText = msg
    },
    /* ---------------------------------------------------*/
    /**
     * 日期组件mutation
     * 
     * @param {any} state 
     * @param {any} status 
     */
    calendar_status(state, status) {
        state.status = status
    },
    calendar_get_date(state) {
        state.date = state.dateYear + '-' + (state.dateMonth > 9 ? state.dateMonth : '0' + state.dateMonth) + '-' + (state.dateDay > 9 ? state.dateDay : '0' + state.dateDay) + ' ' + (state.dateHour > 9 ? state.dateHour : '0' + state.dateHour) + ':' + (state.dateMinute > 9 ? state.dateMinute : '0' + state.dateMinute)
    },
    calendar_date_status(state, date) {
        switch (date.type) {
            case 'year': state.dateYear = date.d; break;
            case 'month': state.dateMonth = date.d; break;
            case 'day': state.dateDay = date.d; break;
            case 'hour': state.dateHour = date.d; break;
            case 'minute': state.dateMinute = date.d; break;
        }
    },
    calendar_choice(state, status) {
        state.ok = status
    },
    comm_mark_status(state, status) {
        state.mark = status
    },
    /* ---------------------------------------------------*/
    [DEGREE_TYPE](state, type) { // 维修紧急程度
        state.degreeType = type
    },
    [IS_LOADING](state, data) { // 加载
        state.is_loading = data
    },
    [MAINTAIN_INFO](state, data) {// 申请维护信息
        state.maintain_info = data
    },
    [RECORD_ADDRESS](state, data) { // 记录经纬度
        let coord = JSON.stringify(data)
        window.sessionStorage.setItem('coordinate', coord)
        state.lon = data.lon
        state.lat = data.lat
    },
    [ADDRESS](state, data) { // 记录用户当前地址
        window.sessionStorage.setItem('address', data)
        state.curAddress = data
    },
    [CONTACTSID](state, data) { // 申请维护老用户id
        state.contacts_id = data
    }
}